package com.onemile.data;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DXmlHead
{
   public static final String ver="1.0";
   public static final int DEFAULT_PAGE_SIZE = 10;
   public static final int MAX_RECORD_COUNT = 50;
   private final String SUCCESS_CODE = "000000000000";

   private String Version;
   private String PostTime;
   private String APICode;
   private int PageNo;
   private int PageSize;
   private int PageCount;
   private boolean UseGZip;
   private String RspCode;
   private String RspMsg;

   public String getVersion()
   {
	  return Version;
   }

   public void setVersion(String version)
   {
	  Version = version;
   }

   public String getPostTime()
   {
	  return PostTime;
   }

   public void setPostTime(String postTime)
   {
	  PostTime = postTime;
   }

   public String getAPICode()
   {
	  return APICode;
   }

   public void setAPICode(String aPICode)
   {
	  APICode = aPICode;
   }

   public int getPageNo()
   {
	  return PageNo;
   }

   public void setPageNo(int pageNo)
   {
	  PageNo = pageNo;
   }

   public int getPageSize()
   {
	  return PageSize;
   }

   public void setPageSize(int pageSize)
   {
	  PageSize = pageSize;
   }

   public int getPageCount()
   {
	  return PageCount;
   }

   public void setPageCount(int pageCount)
   {
	  PageCount = pageCount;
   }

   public boolean getUseGZip()
   {
	  return UseGZip;
   }

   public void setUseGZip(boolean useGZip)
   {
	  UseGZip = useGZip;
   }

   public String getRspCode()
   {
	  return RspCode;
   }

   public void setRspCode(String rspCode)
   {
	  RspCode = rspCode;
   }

   public String getRspMsg()
   {
	  return RspMsg;
   }

   public void setRspMsg(String rspMsg)
   {
	  RspMsg = rspMsg;
   }

   public DXmlHead()
   {

   }

   public DXmlHead(String _APICode)
   {
	  Version = ver;
      Date date = new Date(System.currentTimeMillis());
      PostTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	  APICode = _APICode;
	  PageNo = 1;
	  PageSize = DEFAULT_PAGE_SIZE;
	  PageCount = 0;
	  UseGZip = false;
	  RspCode = SUCCESS_CODE;
	  RspMsg = "";   
   }
   public DXmlHead(String _APICode,boolean _UseGZip)
   {
	  Version = ver;
      Date date = new Date(System.currentTimeMillis());
      PostTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	  APICode = _APICode;
	  PageNo = 1;
	  PageSize = DEFAULT_PAGE_SIZE;
	  PageCount = 0;
	  UseGZip = _UseGZip;
	  RspCode = SUCCESS_CODE;
	  RspMsg = ""; 
   }
   public DXmlHead(String _APICode,int _PageNo)
   {
	  Version = ver;
      Date date = new Date(System.currentTimeMillis());
      PostTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	  APICode = _APICode;
	  PageNo = _PageNo;
	  PageSize = DEFAULT_PAGE_SIZE;
	  PageCount = 0;
	  UseGZip = false;
	  RspCode = SUCCESS_CODE;
	  RspMsg = "";  
   }
   public DXmlHead(String _APICode,int _PageNo,int _PageSize)
   {
	  Version = ver;
      Date date = new Date(System.currentTimeMillis());
      PostTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	  APICode = _APICode;
	  PageNo = _PageNo;
	  PageSize = _PageSize;
	  PageCount = 0;
	  UseGZip = false;
	  RspCode = SUCCESS_CODE;
	  RspMsg = "";  
   }
   
   public DXmlHead(DXml.HeadField head)
   {
	  Version = head.GetFieldValue("Version");
	  PostTime = head.GetFieldValue("PostTime");
	  APICode = head.GetFieldValue("APICode");
	  PageNo = head.GetFieldInt32("PageNo");
	  PageSize = head.GetFieldInt32("PageSize");
	  PageCount = head.GetFieldInt32("PageCount");
	  UseGZip = head.GetFieldValue("UserGZip").equals("1") ? true : false;
	  RspCode = head.GetFieldValue("RepCode");
	  RspMsg = head.GetFieldValue("RspMsg");
   }

   public void FromXML(DXml.HeadField head)
   {
	  Version = head.GetFieldValue("Version");
	  PostTime = head.GetFieldValue("PostTime");
	  APICode = head.GetFieldValue("APICode");
	  PageNo = head.GetFieldInt32("PageNo");
	  PageSize = head.GetFieldInt32("PageSize");
	  PageCount = head.GetFieldInt32("PageCount");
	  UseGZip = head.GetFieldValue("UserGZip").equals("1") ? true : false;
	  RspCode = head.GetFieldValue("RepCode");
	  RspMsg = head.GetFieldValue("RspMsg");
   }

   public void ToXML(DXml.HeadField head)
   {
	  head.Clear();
	  head.AddField("Version", Version);

	  Date date = new Date(System.currentTimeMillis());
	  String t = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	  head.AddField("PostTime", t);

	  head.AddField("APICode", APICode);
	  head.AddField("PageNo", String.valueOf(PageNo));
	  head.AddField("PageSize", String.valueOf(PageSize));
	  head.AddField("PageCount", String.valueOf(PageCount));
	  head.AddField("UseGZip", UseGZip ? "1" : "0");
	  head.AddField("RspCode", RspCode);
	  head.AddField("RspMsg", RspMsg);
   }

}
